#include <iostream>
#include <algorithm>

using namespace std;

int ans;
int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

bool ispail(int ret)
{
	string s = to_string(ret);
	string t = s;
	reverse(s.begin(), s.end());
	return s == t;
}

bool isleapyear(int y)
{
	return (y % 4 == 0 && y % 100 != 0) || (y % 400 == 0);
}

bool isvaild(int y, int m, int d)
{
	if(isleapyear(y) && m == 2) return m >= 0 && m <= 12 && d >= 0 && d <= mon[m] + 1;
	else return m >= 0 && m <= 12 && d >= 0 && d <= mon[m];
}


int main()
{
	int x, y; cin >> x >> y;
	
	for(int i = x; i <= y; i++)
	{
		int year = i / 10000;
		int m = i / 100 % 100;
		int d = i% 100;
		if(isvaild(year, m, d) && ispail(i)) ans++;
	}
	
	cout << ans << endl;
	
	return 0;
}
